package com.xingkeduo.business.operation.service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.VendorQuery;
import com.xingkeduo.pojo.table.VendorTable;
import com.xingkeduo.util.pojo.domain.Page;
import com.xingkeduo.util.tool.CommonUtil;
import com.xingkeduo.util.tool.IdentityUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件概述
 *
 * @author wangxilong <wangxilong@xingkeduo.com>
 * @version id:v0.1 ${date}${time}
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class VendorService {
    private static final String NAMESPACE = VendorTable.class.getSimpleName();

    @Resource(name = "mysqlOperationDao")
    private DatabaseAccessObject<VendorTable, VendorQuery> dao;

    //查询一条
    public VendorTable selectById(long id) throws Throwable {
        VendorTable vendorTable = dao.select(NAMESPACE, id);
        if (!CommonUtil.isEmpty(vendorTable))
            return vendorTable;
        return null;
    }

    //查询一条
    public VendorTable selectByCode(long code) throws Throwable {
        VendorTable vendorTable = dao.select(NAMESPACE, code);
        if (!CommonUtil.isEmpty(vendorTable))
            return vendorTable;
        return null;
    }

    //查询多条
    public List<VendorTable> selectVendors(VendorQuery vendorQuery) throws Throwable {
        List<VendorTable> vendorTableList = dao.select(NAMESPACE, vendorQuery);
        if (!CommonUtil.isEmpty(vendorTableList))
            return vendorTableList;
        return null;
    }

    //分页查询
    public Page<VendorTable> selectPageLists(VendorQuery vendorQuery, Integer pageNo, Integer pageSize) throws Throwable {
        Page<VendorTable> vendorTablePage = dao.pageSelect(NAMESPACE,vendorQuery,pageNo,pageSize);
        return vendorTablePage;
    }

    //插入
    public int insert(VendorTable vendorTable) throws Throwable {
        Long code = IdentityUtil.nextId(IdentityUtil.Worker.DEFAULT);
        vendorTable.setCode(code);
        return dao.insert(NAMESPACE, vendorTable);
    }

    //更新
    public int update(VendorTable vendorTable) throws Throwable {
        return dao.update(NAMESPACE, vendorTable);
    }

    public int delete(VendorTable vendorTable) throws Throwable {
        return dao.update(NAMESPACE, vendorTable);
    }

    //批量
    public int updateRows(VendorTable vendorTable,VendorQuery vendorQuery) throws Throwable {
        return dao.update(NAMESPACE,vendorTable,vendorQuery);
    }

    //数量
    public int count(VendorQuery vendorQuery) throws Throwable {
        return dao.selectCount(NAMESPACE, vendorQuery);
    }
}
